package org.example.xsda.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.example.xsda.common.Result;
import org.example.xsda.entity.SysRole;
import org.example.xsda.mapper.SysRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 角色控制器
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @GetMapping("/list")
    @SaCheckRole(value = {"admin", "teacher"}, mode = SaMode.OR)
    public Result<List<SysRole>> list() {
        LambdaQueryWrapper<SysRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByAsc(SysRole::getId);
        List<SysRole> list = sysRoleMapper.selectList(wrapper);
        return Result.success(list);
    }
}

